﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Collections.Specialized;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace StoragePeriod.COMP
{
    public class PageService
    {
        /// <summary>
        /// 根据名称集合获得所对应的值集合
        /// </summary>
        /// <param name="names">名称集合</param>
        /// <returns>值集合</returns>
        public static List<string> GetListStringByNames(List<string> names,HttpRequest request)
        {
            NameValueCollection nvc = request.Form;
            List<List<string>> nameValues = new List<List<string>>();
            foreach (string name in names)
            {
                if (nvc.GetValues(name) == null)
                {
                    return null;
                }
                nameValues.Add(nvc.GetValues(name).ToList<string>());
            }
            StringBuilder[] sbNameValues = new StringBuilder[nameValues.Count];
            int i = 0;
            foreach (List<string> nameValue in nameValues)
            {
                sbNameValues[i] = new StringBuilder();
                foreach (string value in nameValue)
                {
                    sbNameValues[i].Append(StringUtil.safety(value)).Append(",");
                }
                sbNameValues[i].Remove(sbNameValues[i].Length - 1, 1);
                i++;
            }
            return GetListString(sbNameValues);
        }

        /// <summary>
        /// 将StringBuilder数组转化为string泛型集合
        /// </summary>
        /// <param name="sbs"></param>
        /// <returns>string集合</returns>
        public static List<string> GetListString(StringBuilder[] sbs)
        {
            List<string> listString = new List<string>();
            foreach (StringBuilder sb in sbs)
            {
                listString.Add(sb.ToString());
            }
            return listString;
        }

        

        



        /// <summary>
        /// 获取错误页
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        public static string GetErrorPage(string info)
        {
            return @"<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>
<html xmlns='http://www.w3.org/1999/xhtml'>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
<style type='text/css'>
*{ margin:0; padding:0}
.Error{ background:url(/images/nopurview/ss.gif) 0 0 no-repeat; margin:30px auto; width:465px; height:210px;}

.Error img{ border:0; float:left; margin-left:85px;}

.Error td{ padding-top:10px;}

.Error a{ background:url(/images/nopurview/login.gif) 0 0 no-repeat; display:block; width:74px; height:19px; float:left;}

.Error a:hover{ background:url(/images/nopurview/login2.gif) 0 0 no-repeat; display:block; width:74px; height:19px;}
</style>
<title>" + info + @"</title>
</head>

<body>
<table width='465' border='0' cellspacing='0' cellpadding='0' class='Error'>
  <tr>
    <td valign='middle'>
    <center>
    " + info + @"
    </center></td>
  </tr>
</table>
</body>
</html>";
        }

    }
}
